// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require("base");
    var router = require("../hash/pageRouter");
    var dialog = require("dialog");
    var validate = require("validate");
    var databind = require("databind");
    var css_detail_info = require("../financing/financingDetailInfo.css");
    var css_categorys = require("../main/financingDetailEvidentiaryCategorys.css");
    var js_detail_info =  require("./financingDetailInfo.js");
    var tools = require("tools");
    var pageIndex = 1,
        pageSize = 10,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
    var financeId = "";
    var fileName;
    var init = function(page){
    	
    	financeId = page.params.financeId||base.getUrlParam("financeId");
		initEvent();
		js_detail_info.init(page);
		$(".d2").css("background","url(../../../res/png/tab_bg3.png) no-repeat bottom");
		showEvidentiaryCategorys();
		router.init();
    };
	var initEvent = function(){
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		//点击首页
		$(".platform_main").unbind("click").click(function(){
			top.location.href = "../main/platform_main.html";
		});
		//待审批列表
		$(".financeApproveList").unbind("click").click(function(){
			router.route("main/main_finance.html?left=0&financeState=1", true);
		});
    };
    
    var showEvidentiaryCategorys = function(){
    	base.fnAjax({
            action: "inquireFinanceApplicationDetail.json",
            oData: {
            	
            	financeId: financeId
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	if(data.datas[0].evidentiaryCategorys.length==0){
                		$("#evidentiaryCategorysBody").html("暂无数据");
                	}else{
                		var tpl = $("#evidentiaryCategorysTpl").html();
	                	var html = juicer(tpl, data);
	                	$("#evidentiaryCategorysBody").html(html);
	                	var materialItems = $(".materialItem");
	                	for(var j = 0; j<materialItems.length; j++){
	                		$(materialItems[j]).find(".d11 span").html(tools.inquireFile($(materialItems[j]).find(".d11").attr("materialFileuuid")));
	                		for (var k=materialItems.length-j+1;k>1;k--){
	                			if($(materialItems[k]).attr("templateId") == $(materialItems[k-1]).attr("templateId")){
	                				$(materialItems[k]).find(".d1").clone().appendTo($(materialItems[k-1]));
	                				$(materialItems[k]).remove();
	                				k = 1;
	                			}
	                		}
                		}
                	}
                } else {
                     base.alert(2,"信息获取失败");
                }
            }
        });
    	
    }
    return {
        init:init
    };
});